import 'package:ffloat/ffloat.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_demo/config/colors.dart';
import 'package:flutter_demo/config/dimens.dart';
import 'package:flutter_demo/util/screen_util.dart';
import 'package:fradio/fradio.dart';
import 'package:fsuper/fsuper.dart';

typedef _ClickCallBack = void Function(int selectIndex);

class FFloatButton extends StatelessWidget {
  final List<String> clickList;
  int group_vule;
  FFloatController controller;
  String selectedContent;
  double width;
  double height;
  Color bgColor;
  _ClickCallBack clickCallBack;

  FFloatButton({
    @required this.clickList,
    @required this.controller,
    @required this.selectedContent,
    this.group_vule = -1,
    this.width,
    this.height,
    this.bgColor = Colours.bg_color,
    this.clickCallBack
  });

  @override
  Widget build(BuildContext context) {
    return cornerDemo();
  }

  FFloat cornerDemo() {
    return FFloat(
      (setter) {
        return SizedBox(
          width: width == null ? ScreenAdaptive.width(180) : width,
          height: (ScreenAdaptive.height(50) + ScreenAdaptive.height(5)) *
              clickList.length,
          child: ListView.builder(
              shrinkWrap: true,
              padding: EdgeInsets.zero,
              itemCount: clickList.length,
              itemBuilder: (context, index) {
                return FRadio.custom(
                  value: index,
                  groupValue: group_vule,
                  onChanged: (value) {
                    setter(() {
                      controller.dismiss();
                      clickCallBack(value);
                      group_vule = value;
                    });
                  },
                  normal: FSuper(
                    width: double.infinity,
                    height: ScreenAdaptive.height(50),
                    textAlign: TextAlign.center,
                    textAlignment: Alignment.center,
                    text: clickList[index],
                    style: TextStyle(
                        color: Colours.color_28,
                        fontSize: ScreenAdaptive.sp(30)),
                  ),
                  selected: FSuper(
                    width: double.infinity,
                    height: ScreenAdaptive.height(50),
                    textAlign: TextAlign.center,
                    textAlignment: Alignment.center,
                    text: clickList[index],
                    style: TextStyle(
                        color: Colours.redColor,
                        fontSize: ScreenAdaptive.sp(30)),
                    backgroundColor: Colors.white,
                  ),
                );
              }),
        );
      },
      anchor: buildContainer(),
      controller: controller,
      color: Colors.white,
      corner: FFloatCorner.all(6),
      strokeColor: Colors.grey,
      //弹窗边框
      strokeWidth: 0,
      alignment: FFloatAlignment.bottomLeft,
    );
  }

  Widget buildContainer() {
    return Container(
      height: ScreenAdaptive.height(68),
      width: width,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(color: Colours.bg_color,width: Dimens.dHeight1,),
        borderRadius: BorderRadius.circular(Dimens.dHeight6)
      ),
      child: Row(
        children: [
          Dimens.sizeBox_w29,
          Text(
            selectedContent,
            style:
                TextStyle(color: Colours.color_65, fontSize: Dimens.font_sp26),
          ),
          Expanded(child: SizedBox()),
          Icon(Icons.arrow_drop_down,size: Dimens.dWidth24,),
          Dimens.sizeBox_w23
        ],
      ),
    );
  }
}
